<!-- loading.vue组件 -->
<template>
  <div class="loading-box" v-show="show">
        <div class="loading-mask"></div>
        <div class="loading-content">
            <div class="animate">
            </div>
            <div class="text">{{text}}</div>
        </div>
    </div>

</template>

<script>
export default {
 data () {
    return {
      durationNum: 1000
    }
  },
  props: {
    show: Boolean,
    text: {
      type: String,
      default: "正在加载中..."
    },
    duration:{
      type:Number,
      default :3000
    }
  },
  methods:{

  },
  mounted(){
    console.log(this)
  },
  watch:{
    show:function(val, oldVal){   //watch里面 监听时 用箭头函数会导致this指向怪异
      if(val){
        console.log(this)
      this.timer= setTimeout(() => {
        this.show = false
      }, this.duration);
    }
    }

  },
  beforeDestroy(){
    clearTimeout(this.timer)
  }
};
</script>
<style>
.loading-box {
  padding: 0.5rem;
  border-radius: 5%;
  text-align: center;
  background-color:#000;
  background: rgba(0, 0, 0, 0.4);
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.text{
  font-size: 0.35rem;
  color: #fff;
}
</style>
